//封装组合式API有一定的规范

import { onMounted, onUnmounted, ref } from "vue"



export function useWidth (){
//   const width = ref(window.innerWidth)
const width = ref(0)

const changeSize = () => {
  width.value = window.innerWidth
}



onMounted(() => {
  window.addEventListener('resize', changeSize)
})

onUnmounted(() => {
  window.removeEventListener('resize', changeSize)
})

return {
  width
}
}